package com.jy.rhin.zhibiao.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jy.rhin.zhibiao.model.dto.PingTaiDYCSDto;
import com.jy.rhin.zhibiao.model.dto.ZhiBiaoDto;
import com.jy.rhin.zhibiao.model.po.ZhiBiaoPo;
import com.jy.rhin.zhibiao.service.PingTaiDYCSService;
import com.jy.rhin.zhibiao.service.ZhiBiaoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jy.framework.base.entity.Result;
import com.jy.rhin.infra.repo.zhibiao.assembler.ZhiBiaoAssembler;

import java.util.List;

/**
 * @author yuyue
 * @date 2024/3/22
 */
@Api("常量指标")
@RestController
@RequestMapping("zhiBiao")
public class ZhiBiaoController {

    @Autowired
    private ZhiBiaoService zhiBiaoService;
    @Autowired
    private PingTaiDYCSService pingTaiDYCSService;

    @GetMapping("leiXing")
    public Result<List<ZhiBiaoDto>> getZhiBiaoLX() {
        List<ZhiBiaoPo> list = zhiBiaoService.list(Wrappers.<ZhiBiaoPo>lambdaQuery()
                .eq(ZhiBiaoPo::getType, 1));
        return Result.success(ZhiBiaoAssembler.poListToDtoList(list));
    }

    @GetMapping("listByLXId")
    public Result<List<ZhiBiaoDto>> getZhiBiaoList(@RequestParam(required = false) String zhiBiaoLXId) {
        List<ZhiBiaoPo> list = zhiBiaoService.list(Wrappers.<ZhiBiaoPo>lambdaQuery()
                .eq(ZhiBiaoPo::getType, 2)
                .eq(StrUtil.isNotBlank(zhiBiaoLXId), ZhiBiaoPo::getShangJiId, zhiBiaoLXId));
        return Result.success(ZhiBiaoAssembler.poListToDtoList(list));
    }

    @GetMapping("page")
    @ApiImplicitParam(name = "shiJianWD", value = "1: 年，2: 月，3: 日")
    public Result<Page<PingTaiDYCSDto>> getPage(@RequestParam Integer shiJianWD,
                                                @RequestParam(required = false) String startDate,
                                                @RequestParam(required = false) String endDate,
                                                @RequestParam(required = false) String zhiBiaoLX,
                                                @RequestParam(required = false) String zhiBiaoDM,
                                                @RequestParam(defaultValue = "1") Integer pageNo,
                                                @RequestParam(defaultValue = "10") Integer pageSize) {
        return Result.success(pingTaiDYCSService.getPage(shiJianWD, startDate, endDate, zhiBiaoLX, zhiBiaoDM, pageNo, pageSize));
    }

    @PostMapping("tongJiDYCS")
    public void tongJiDYCS(@RequestParam String date) {
        pingTaiDYCSService.tongJiDYCS(date);
    }

}
